#!/usr/bin/env python
from glob import glob
import sys
import os

dir_0 = sys.argv[1]
if not os.path.exists(dir_0+"_fits"):
    os.system("mkdir "+dir_0+"_fits")
files = glob(dir_0+"/*.bin")
for f in files:
    os.system("bin2fits.py "+f+" -o")
    os.system("mv "+f[:-3]+"fits"+" "+dir_0+"_fits/"+f.split('/')[-1][:-3]+"fits")
